﻿using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Media;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TestGame {
    /// <summary>
    /// The GameOverScreen, which is intended to be placed over the any GamePlayScreen.
    /// It prompts the user if they would like to replay, return to the main menu, or
    /// exit the game. 
    /// </summary>
    class GameOverScreen : MenuScreen {
        #region Fields

        ContentManager content;

        #endregion

        #region Constructor

        public GameOverScreen() : base("Game Over!") {
            // Create our menu entries.
            MenuEntry replayGameMenuEntry = new MenuEntry("Replay");
            MenuEntry resumeGameMenuEntry = new MenuEntry("Return to Main Menu");
            MenuEntry quitGameMenuEntry = new MenuEntry("Quit Game");

            // Hook up menu event handlers.
            replayGameMenuEntry.Selected += ReplaySelected;
            resumeGameMenuEntry.Selected += MainMenuSelected;
            quitGameMenuEntry.Selected += QuitGameSelected;

            // Add entries to the menu.
            MenuEntries.Add(replayGameMenuEntry);
            MenuEntries.Add(resumeGameMenuEntry);
            MenuEntries.Add(quitGameMenuEntry);
        }

        #endregion

        #region Content Management

        /// <summary>
        /// Loads the Content for the GameOverScreen. 
        /// </summary>
        public override void LoadContent() {
            base.LoadContent();

            if (content == null) {
                content = new ContentManager(ScreenManager.Game.Services, "Content");
            }

            Song gameOverSong = content.Load<Song>("music/GameOver");
            MediaPlayer.Play(gameOverSong);
        }

        /// <summary>
        /// Unloads the Content for the GameOverScreen and stops any Songs playing.
        /// </summary>
        public override void UnloadContent() {
            base.UnloadContent();
            MediaPlayer.Stop();
        }

        #endregion

        #region Event Handlers

        void ReplaySelected(object sender, PlayerIndexEventArgs e) {
            LoadingScreen.Load(ScreenManager, false, e.PlayerIndex, new SinglePlayerScreen());
        }

        void MainMenuSelected(object sender, PlayerIndexEventArgs e) {
            LoadingScreen.Load(ScreenManager, false, e.PlayerIndex, new BackgroundScreen(), new MainMenuScreen());
        }

        void QuitGameSelected(object sender, PlayerIndexEventArgs e) {
            ScreenManager.Game.Exit();
        }

        #endregion
    }
}
